module.exports = function rikoWidget (init) {

  function Widget (options) {
    if (!(this instanceof Widget)) return new Widget(options);
    this.options = options;
  }

  Widget.prototype.type = "Widget";

  Widget.prototype.init = function () {
    this.state = init(this.options);
    return this.state.element;
  }

  Widget.prototype.update = function (previous) {
    this.state = previous.state;
    return this.state.update ? this.state.update.apply(this, arguments) : null
  }

  Widget.prototype.destroy = function () {
    if (this.state.destroy) this.state.destroy.apply(this, arguments)
  }

  return Widget;

}
